/*
	Copyright (C) 2013 Pontificia Universidad Catolica del Peru
	contact: http://avatar.inf.pucp.edu.pe/realidad-aumentada/
	address contact: Av. Universitaria 1801, San Miguel, Lima-Peru.
	
	This file is part of UbicAR PUCP.

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with This program.  If not, see <http://www.gnu.org/licenses/>.
*/
/*
	Author: Pedro Carrión Castagnola
	Pontificia Universidad Catolica del Peru
	Direccion de Informatica Academica
	
	Modified by: Alvaro Roger Agüero Sánchez, Rodolfo Javier Galvez Meza
	Pontificia Universidad Catolica del Peru
	Departamento de Ingeniería
*/

package org.grupoavatar.guiaubicua.entidades;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import org.grupoavatar.guiaubicua.R;

public class ListaPOIAdapter extends ArrayAdapter<ListaPOIRow>{

    Context context; 
    int layoutResourceId;    
    ListaPOIRow data[] = null;
    
    public ListaPOIAdapter(Context context, int layoutResourceId, ListaPOIRow[] data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ListaPOIHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new ListaPOIHolder();
            holder.imgIcon = (ImageView)row.findViewById(R.id.imgIconListPOI);
            holder.txtTitle = (TextView)row.findViewById(R.id.txtTitleListPOI);
            //holder.txtDistancia = (TextView)row.findViewById(R.id.txtDistanceListPOI);
            
            row.setTag(holder);
        }
        else
        {
            holder = (ListaPOIHolder)row.getTag();
        }
        if (data != null) {
	        ListaPOIRow poi = data[position];
	        holder.txtTitle.setText(poi.title);
	        //holder.txtDistancia.setText(poi.distancia);
	        holder.imgIcon.setImageResource(poi.icon);
        } else {
        	holder.txtTitle.setText("");
        }
        return row;
    }
    
    static class ListaPOIHolder
    {
        ImageView imgIcon;
        TextView txtTitle;
        //TextView txtDistancia;
    }
}